package com.tenpines.test.helper;

/**
 * Represents a timeout event.
 * 
 * @author egutter
 * 
 */
public class Timeout {

	private final long endTime;

	/**
	 * Builds a new timeout with its expected duration.
	 * 
	 * @param duration
	 */
	public Timeout(long duration) {
		this.endTime = System.currentTimeMillis() + duration;
	}

	/**
	 * Returns <b>true</b> if the timeout has been met.
	 * 
	 * @return
	 */
	public boolean hasTimedOut() {
		return timeRemaining() <= 0;
	}

	private long timeRemaining() {
		return endTime - System.currentTimeMillis();
	}

}
